|
ARD2
RC2
Airbag Reference Demonstrator using MPC5604P
|
00001 00016 #include "derivative.h" 00017 #include "compile_options.h" 00018 #include "HAL.h" 00019 #include "Acquisition.h" 00020 #include "SM.h" 00021 #include "SBC_AL.h" 00022 #include "Central_Accel_AL.h" 00023 #include "MailScheduler.h" 00024 #include "Application_Globals.h" 00025 /* 00026 ****************************************************************************** 00027 * Constants 00028 ****************************************************************************** 00029 */ 00031 const uint16_t cau16PreAcquiValidStates[] = 00032 { 00033 SM_STATE_SETUP, SM_STATE_ERROR, SM_STATE_GUI, SM_STATE_DEPLOYMENT }; 00034 /* 00035 ****************************************************************************** 00036 * Globals 00037 ****************************************************************************** 00038 */ 00039 00040 /* 00041 ****************************************************************************** 00042 * u32fnStateAcquisition 00043 ****************************************************************************** 00044 */ 00045 uint32_t u32fnStateAcquisition(void) 00046 { 00047 uint32_t u32Status; 00048 00049 /* State variable listing follows */ 00050 uint32_t au32PSI5SatRawResponses[20u]; 00051 uint16_t au16CentralAccelRawResponses[20u]; 00052 uint8_t u8Tries; 00053 uint8_t u8PerformFilter; 00054 00055 /* Verify that we can execute - Previous state ended correctly */ 00056 u32Status = u32fnSMValidateCurrentState((uint16_t*)cau16PreAcquiValidStates, 00057 N_ELEMENTS(cau16PreAcquiValidStates)); 00058 if(CLEAR == u32Status) 00059 { 00060 /* Here comes the real contents of the state */ 00061 LOCK_STATE_EXECUTION(); 00062 /*-----------------------------------------------------------------------*/ 00063 /* Init tries counter */ 00064 u8Tries = CLEAR; 00065 00066 /* Init the Perform Filter */ 00067 u8PerformFilter = (PERFORM_CA | PERFORM_PSI); 00068 /* Schedule acceleration from all sensors */ 00069 /* Read Reference accelerometer: Results should be placed in an array */ 00070 00071 #ifdef USE_AUTO_SYNC 00072 while((SCHED_100US_PERIOD * 4u) > u32fnSchedHasTimeElapsed(gu32SMCycleStartTime)) 00073 { 00074 /* We need to ensure enough time has passed before reading */ 00075 } 00076 #else 00077 /* Synchronize with WD - otherwise we might have timing issues */ 00078 /* Note that the chosen sync time is not arbitrary, but a requirement */ 00079 /* to ensure proper WD deployment once a firing event has occurred. */ 00080 (void)u8fnSBCSyncSM(1u); 00081 00082 /* Send Sync */ 00083 (void)u8fnSBCSchedulePSync(); 00084 #endif 00085 do 00086 { 00087 u32Status = CLEAR; 00088 /* Read back PSI5 sensors through SBC: Results are placed in the same */ 00089 /* array as the main accelerometer's array. */ 00090 if(u8PerformFilter & PERFORM_CA) 00091 { 00092 u32Status = u32fnCAScheduleAccelXY((uint16_t*)&au16CentralAccelRawResponses); 00093 } 00094 else 00095 { 00096 /* Don't Perform */ 00097 } 00098 if(CLEAR == u32Status) 00099 { 00100 /* Message got scheduled correctly */ 00101 u8PerformFilter &= ~PERFORM_CA; 00102 00103 00104 if(u8PerformFilter & PERFORM_PSI) 00105 { 00106 u32Status = u32fnSBCSchedulePSISat((uint16_t*)&au32PSI5SatRawResponses); 00107 } 00108 else 00109 { 00110 /* Don't perform */ 00111 } 00112 00113 /***** Seat-buckle reading should be performed at this time. *****/ 00114 00115 if(CLEAR == u32Status) 00116 { 00117 /* Message got scheduled correctly */ 00118 u8PerformFilter &= ~PERFORM_PSI; 00119 } 00120 else 00121 { 00122 00123 } 00124 00125 } /* End if scheduling central accelerometer */ 00126 else 00127 { 00128 /* Not happy about central accelerometer data */ 00129 } /* End else scheduling central accelerometer */ 00130 00131 while(1 > u32fnSchedIsTxDone(gu32SBCTime)) 00132 { 00133 /* Wait here */ 00134 }; 00135 SCHED_WHAT_IS_THE_TIME(gu32SMCycleStartTime); 00136 }while((CLEAR != u32Status) &(MAX_NUMBER_OF_ACQUI_SCHEDULING_TRIES > u8Tries++)); 00137 00138 if(CLEAR == u32Status) 00139 { 00140 /* Note that for Mesquite/Sycamore, the first byte is throw- */ 00141 /* away and will be overwritten next. */ 00142 u32Status = u32fnCAExtractXY((uint16_t*)au16CentralAccelRawResponses, 00143 (uint16_t*)&(gau16RawAccels[SM_CA_GLOBAL_INDEX])); 00144 00145 /* Interpret acceleration from all devices */ 00146 u32Status |= u32fnSBCExtractPSISat((uint16_t*)&au32PSI5SatRawResponses, 00147 (uint16_t*)&(gau16RawAccels[SM_PSI5_GLOBAL_INDEX])); 00148 00149 /* Verify that we still have satellites */ 00150 if(CLEAR != gu16ActivePSI5Channels) 00151 { 00152 /* We will continue to loop */ 00153 } 00154 else 00155 { 00156 /* Force the status to all satellites crashed - we will treat in */ 00157 /* the error case. */ 00158 u32Status |= (SAT_CH0_SLOT0_CRASHED | SAT_CH0_SLOT1_CRASHED | 00159 SAT_CH0_SLOT2_CRASHED | SAT_CH1_SLOT0_CRASHED | 00160 SAT_CH1_SLOT1_CRASHED | SAT_CH1_SLOT2_CRASHED | 00161 SAT_CH2_SLOT0_CRASHED | SAT_CH2_SLOT1_CRASHED | 00162 SAT_CH2_SLOT2_CRASHED | SAT_CH3_SLOT0_CRASHED | 00163 SAT_CH3_SLOT1_CRASHED | SAT_CH3_SLOT2_CRASHED); 00164 } 00165 00166 00167 } 00168 else 00169 { 00170 /* Exit already */ 00171 } 00172 00173 /*-----------------------------------------------------------------------*/ 00174 00175 /* Unlock the state */ 00176 UNLOCK_STATE_EXECUTION(); 00177 } /* End if for State is valid */ 00178 else 00179 { 00180 /* Leave */ 00181 } /* End else for State is valid */ 00182 00183 /* Set the next state */ 00184 if(CLEAR == u32Status) 00185 { 00186 vfnSMWriteNextState(SM_STATE_DECISION); 00187 } 00188 else 00189 { 00190 vfnSMWriteNextState(SM_STATE_ERROR); 00191 } 00192 return (u32Status); 00193 } 00194 /* 00195 ****************************************************************************** 00196 * 00197 * End of file. 00198 * 00199 ****************************************************************************** 00200 */